package net.koodar.forge.system.support.operateLog.model.dto;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import net.koodar.forge.mybatis.doman.page.AbstractPageQuery;
import net.koodar.forge.system.support.operateLog.model.entity.OperateLog;

import java.util.Date;

/**
 * @author liyc
 */
@Setter
@Getter
public class OperateLogQueryDTO extends AbstractPageQuery<OperateLog> {

	private String username;

	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss")
	private Date startDate;

	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd hh:mm:ss")
	private Date endDate;

	private Boolean successFlag;

	@Override
	public QueryWrapper<OperateLog> addQueryCondition() {
		QueryWrapper<OperateLog> queryWrapper = Wrappers.query();
		queryWrapper.eq(StrUtil.isNotBlank(username), "operate_user_name", username);
		queryWrapper.ge(startDate != null, "create_time", startDate);
		queryWrapper.le(endDate != null, "create_time", endDate);
		queryWrapper.eq(successFlag != null, "success_flag", successFlag);
		return queryWrapper;
	}
}
